const net = require('net');
const fs = require('fs');
const CryptoJS = require("crypto-js");
const crypto = require('crypto');
const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  });

rl.question("URL >", url => {
    rl.question("Password >", password => {
        bytes = CryptoJS.AES.decrypt(url.split('::')[0], password);
        decryptedURL = bytes.toString(CryptoJS.enc.Utf8);
        
        const client = net.createConnection({port: 4000, host: decryptedURL}, () => {
            console.log((new Date()), "Connected to the remote node");
            const request = CryptoJS.AES.encrypt(`GET ${url.split('::')[1]}`, password).toString();
            client.write(request);
        })

        client.on("data", (data) => {
            data = data.toString('utf8');
            data = CryptoJS.AES.decrypt(data, password);
            data = data.toString(CryptoJS.enc.Utf8);
            data = data.toString('utf8');

            console.log((new Date()), data);
        });
    })
    
});

